package com.hjq.mallcart.entity;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

/**
 * @auther HJQ
 */
public class Cart {
    private List<CartItem> cartItems=new ArrayList<>();
    private Integer count;
    private Integer countType;
    private BigDecimal totalAmount;
    private  BigDecimal reduce=new BigDecimal(0);

    public List<CartItem> getCartItems() {
        return cartItems;
    }

    public void setCartItems(List<CartItem> cartItems) {
        this.cartItems = cartItems;
    }

    public Integer getCount() {
        if(cartItems!=null&&cartItems.size()>0){
           Integer sum=0;
            for (CartItem item : cartItems) {
                sum+=item.getCount();
            }
            return  sum;


        }
        return 0;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public Integer getCountType() {
        return cartItems.size();
    }

    public void setCountType(Integer countType) {
        this.countType = countType;
    }

    public BigDecimal getTotalAmount() {
        if(cartItems!=null&&cartItems.size()>0){
            BigDecimal sum=new BigDecimal(0);
            for (CartItem item : cartItems) {
                if(item.getChecked()) {
                    sum = sum.add(item.getTotalPrice());
                }
            }
            //减去优惠总价
            sum=sum.subtract(reduce);
            return  sum;


        }
        return new BigDecimal(0);
    }

    public void setTotalAmount(BigDecimal totalAmount) {
        this.totalAmount = totalAmount;
    }

    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }
}
